package com.parsechina.hpush.broker.internal.message;

import com.parsechina.hpush.broker.parser.PublishMessage;
import com.parsechina.hpush.broker.utils.ByteUtils;

/**
 * @author linfeng
 * @since 2016/12/9
 */
public class NotifyPublishMessage extends NotifyAbstractMessage {

    private static final long serialVersionUID = 97468680331960681L;
    private final String clientId;
    private final String username;
    private final int qos;
    private final byte[] payload;
    private final String topic;
    private final Boolean retained;

    public NotifyPublishMessage(String clientId, String username, PublishMessage publishMessage) {
        super(NotifyType.PUBLISH);
        this.clientId = clientId;
        this.username = username;
        topic = publishMessage.getTopicName();
        qos = publishMessage.getQos().value();
        payload = ByteUtils.convert(publishMessage.getPayload());
        retained = publishMessage.isRetained();
    }

    public int getQos() {
        return qos;
    }

    public byte[] getPayload() {
        return payload;
    }

    public String getTopic() {
        return topic;
    }

    public String getClientId() {
        return clientId;
    }

    public String getUsername() {
        return username;
    }

    public boolean isRetained() {
        return retained;
    }
}
